package com.thd.springboottest.sso.client.vo;

import com.thd.springboottest.sso.vo.AuthBean;

import java.util.*;

/**
 * com.thd.springboottest.sso.client.vo.Store
 *
 * @author: wanglei62
 * @DATE: 2021/8/22 16:04
 **/
public class Store {
    public static Map<String, AuthBean> store = new HashMap<String,AuthBean>();
    public static AuthBean findBySessionId(String sessionId){
        return store.get(sessionId);
    }

    public static AuthBean remove(String sessionId){
        AuthBean r = store.remove(sessionId);
        return r;
    }

    public static void add(AuthBean authBean){
        store.put(authBean.getSessionId(),authBean);
    }

    public static AuthBean getByUsr(String usr){
        Collection<AuthBean> list = store.values();
        Optional<AuthBean> optional = list.stream().filter(item -> {
            return item.getUsr().equalsIgnoreCase(usr);
        }).findFirst();
        if(optional.isPresent()){
            return optional.get();
        }else{
            return null;
        }
    }
}
